//
//  WhzDistrictViewController.m
//  WhzMT
//
//  Created by whz on 16/12/12.
//  Copyright © 2016年 whz. All rights reserved.
//

#import "WhzDistrictViewController.h"

#define CELLIDRIGHT @"cellIdRight"
#define CELLIDLEFT @"cellIdLeft"

@interface WhzDistrictViewController () <UITableViewDelegate, UITableViewDataSource>

/** 选中的一级菜单索引*/
@property(nonatomic, assign)NSInteger currentIndex;

@end

@implementation WhzDistrictViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    [self setupUI];
}

/** 初始化UI*/
- (void)setupUI {

    // 设置 取消 cell 之间的分割线
    self.districtPopoverView.tableViewLeft.separatorStyle = UITableViewCellSeparatorStyleNone;
    self.districtPopoverView.tableViewRight.separatorStyle = UITableViewCellSeparatorStyleNone;
    
    // 设置数据源和代理
    self.districtPopoverView.tableViewLeft.delegate = self;
    self.districtPopoverView.tableViewLeft.dataSource = self;
    self.districtPopoverView.tableViewRight.delegate = self;
    self.districtPopoverView.tableViewRight.dataSource = self;
    
}

#pragma mark - <UITableViewDelegate>

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

    if (tableView == self.districtPopoverView.tableViewLeft) {
        
        self.currentIndex = indexPath.row;
        
        [self.districtPopoverView.tableViewRight reloadData];
        
    } else {
        
        NSLog(@"点击了二级菜单数据");
//        NSLog(@"点击了二级菜单数据，%@",self.categoryModel[self.currentIndex].subcategories[indexPath.row]);
    }
}

#pragma mark - <UITableViewDataSource>

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

    if (tableView == self.districtPopoverView.tableViewLeft) {
        
        return 20;
        
    } else {
    
        return 10;
    }
    
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    UITableViewCell *cell;
    
    if (tableView == self.districtPopoverView.tableViewLeft) {
        
        cell = [tableView dequeueReusableCellWithIdentifier:CELLIDLEFT];
        cell.textLabel.text = @"whz";
        return cell;
        
    } else {
    
        cell = [tableView dequeueReusableCellWithIdentifier:CELLIDRIGHT];
        
        return cell;
    }
}

#pragma mark - 懒加载

- (WhzDistrictPopoverView *)districtPopoverView {

    if (_districtPopoverView == nil) {
        
        _districtPopoverView = [[WhzDistrictPopoverView alloc] init];
        
        [self.view addSubview:_districtPopoverView];
    }
    return _districtPopoverView;
}


@end
